<?php
/**
 * Pipahr
 *
 * @author Chin Win
 * @copyright 2013 pipahr.com
 */
require_once(OC_App::getAppPath('calendar') . "/lib/helper.php");
JLoader::register("PCalendarModellistview", OC_App::getAppPath('calendar') . "/lib/listview.php");

OCP\JSON::callCheck();
if(!OC_User::isLoggedIn()) {
   echo '您需要先登录';
   exit;
}

$jobseekid = JRequest::getInt('jobseekid', 0);
$objectid = JRequest::getInt('objectid', 0);
$object_model = new PCalendarModelObject();

$preview_info = $object_model->getEventPreviewInfo($objectid);
if ( !$preview_info ) {
   jexit(jsonError('没找到任何日程', null, false));
}

$model = new PCalendarModellistview();

$round = $model->getUserInterviewList($jobseekid);

$total = count($round);

if($total==0) {
   echo '没有详细信息';
   exit();
}else{
   $preview_info = $object_model->getEventPreviewInfo($round[0]['parent']);
   if ( !$preview_info ) {
      jexit(jsonError('没找到任何日程', null, false));
   }

   $objecttype = $preview_info['objecttype'];
   if ( $objecttype == 'VEVENT' ) {
      $interviewers = $preview_info['interviewers'] ? $preview_info['interviewers'] : array();
   }
   echo '
      <div id="preview_modal">
      <div class="topsj"></div>
      <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
         <h3 class="songti">'.$preview_info['title_date'].'</h3>
      </div>';
   if ($total==1) {
      $title = '初试';
      if($round[0]['round']!=1){
         $title = '第'.$round[0]['round'].'轮面试';
      }
      $jobid = $round[0]['jobid'];
      echo '
         <div class="modal-body medium">
         <div class="againinterview interviewer_action"><div class="notusediv clearfix"><b class="pull-left">'.$title.'</b> ';
      $allowedit = $object_model->checkObjectEditPermission($round[0]['parent']);
      isset($allowedit) ? $allowedit : false;
      if($allowedit){
         if($round[0]['result'] != PCalendarHelper::INTERVIEW_RESULT_HIRE && $round[0]['result'] != PCalendarHelper::INTERVIEW_RESULT_NOTHIRE) {
            if($round[0]['result'] ==  PCalendarHelper::INTERVIEW_RESULT_CANCEL){
               echo '<a href="javascript:;" data-eventid="'.$objectid.'" data-resultid="'.$round[0]['result'].'" id="editEvent">安排面试</a> | 已取消';
            }else{
               echo '<a data-totalfeedbacks="'.$round[0]['last_round_totalfeedbacks'].'" href="javascript:;" data-eventid="'.$objectid.'" data-validemail="'.(!isFakeEmail($preview_info['email']) ? '1':'0').'" data-resultid="'.$round[0]['result'].'" id="editEvent">修改</a> | <a id="cancelEvent" eventtype="'.$objecttype.'" data="{jobseekid:'.$jobseekid.',jobid:'.$jobid.',eventid:'.$objectid.',validemail:'.(!isFakeEmail($preview_info['email']) ? '1':'0').'}" href="javascript:;">取消面试</a>';
            }
         }
      }
      echo '
         </div></div>
         <div class="contentline_each clearfix"><span>职&nbsp;&nbsp;&nbsp;位：</span><a href="'.OC_Helper::linkToRoute("jobpos_setup", array('id'=>$jobid, 'job_title'=>$round[$total-1]['job_title'])).'" target="_blank">'.$round[$total-1]['job_title'].'</a></div>
         <div class="contentline_each clearfix"><span>姓&nbsp;&nbsp;&nbsp;名：</span><a href="'.OCP\Util::linkToRoute('resume_view', array('id' => $jobseekid,'name'=>JFilterOutput::stringURLUnicodeSlug($round[$total-1]['jobseekername']))).'" target="_blank">'.$round[$total-1]['jobseekername'].'</a></div>
         <div class="contentline_each clearfix"><span>面&nbsp;&nbsp;&nbsp;试：</span>
         <div class="timelist pull-left">
        ';
      if(empty($interviewers)){
         echo '<div class="eachinterviewer">尚未安排面试官面试</div>';
      }else{
         foreach($interviewers as $key =>$lists){
            echo '<div class="eachinterviewer"><span>'.$lists['start_time'].' - '.$lists['end_time'].'</span>'.strmaxtextlen($lists['show_name'],10).'</div>';
         }
      }
      echo '</div>
            </div>
            </div>
            </div>';
      exit();
   }else{
      $jobid = $round[0]['jobid'];
      echo'
         <div class="modal-body medium">
         <div class="againinterview interviewer_action"><div class="notusediv clearfix"><b class="pull-left">第'.($round[0]['round']).'轮面试</b>';
      $allowedit = $object_model->checkObjectEditPermission($round[0]['parent']);
      isset($allowedit) ? $allowedit : false;
      if($allowedit){
         if($round[0]['result'] != PCalendarHelper::INTERVIEW_RESULT_HIRE && $round[0]['result'] != PCalendarHelper::INTERVIEW_RESULT_NOTHIRE) {
            if($round[0]['result'] ==  PCalendarHelper::INTERVIEW_RESULT_CANCEL){
               echo '<a href="javascript:;" data-eventid="'.$objectid.'" data-validemail="'.(!isFakeEmail($preview_info['email']) ? '1':'0').'" data-resultid="'.$round[0]['result'].'" id="editEvent">安排面试</a> | 已取消';
            }else{
               echo '<a data-totalfeedbacks="'.$round[0]['last_round_totalfeedbacks'].'" href="javascript:;" data-eventid="'.$objectid.'" data-resultid="'.$round[0]['result'].'" id="editEvent">修改</a> | <a id="cancelEvent" eventtype="'.$objecttype.'" data="{jobseekid:'.$jobseekid.',jobid:'.$jobid.',eventid:'.$objectid.'}" href="javascript:;">取消面试</a>';
            }
         }
      }
      echo '
         </div></div>
         <div class="contentline_each clearfix"><span>职&nbsp;&nbsp;&nbsp;位：</span><a href="'.OC_Helper::linkToRoute("jobpos_setup", array('id'=>$jobid, 'job_title'=>$round[0]['job_title'])).'" target="_blank">'.$round[0]['job_title'].'</a></div>
         <div class="contentline_each clearfix"><span>姓&nbsp;&nbsp;&nbsp;名：</span><a href="'.OCP\Util::linkToRoute('resume_view', array('id' => $jobseekid,'name'=>JFilterOutput::stringURLUnicodeSlug($round[0]['jobseekername']))).'" target="_blank">'.$round[0]['jobseekername'].'</a></div>
         <div class="contentline_each clearfix"><span>面&nbsp;&nbsp;&nbsp;试：</span>
         <div class="timelist pull-left">';
         foreach($interviewers as $key =>$lists){
            echo '<div class="eachinterviewer"><span>'.$lists['start_time'].' - '.$lists['end_time'].'</span>'.strmaxtextlen($lists['show_name'],10).'</div>';
         }
         echo'</div></div>';
         
         if(0){
         echo'
         <div class="contentline_each clearfix"><span>备&nbsp;&nbsp;&nbsp;注：</span>
            <div class="timelist pull-left">
               <div class="beizhucolor">此人经验丰富，面试时请着重了解下熟悉技能等等。另外，请注意逻辑是否清晰。</div>
            </div>
         </div>';
         }
         
         foreach ($round as $key =>$val){
            if($key != 0){
               $interview = '';
               if($val['round']==1){
                  $interview='初试';
               }else{
                  $interview='第'.($val['round']).'轮面试';
               }
               echo'
                  <div class="interviewer_action">
                  <div class="notusediv clearfix">
                  <b class="pull-left">'.$interview.'</b><em class="pull-left">'. JHtml::_('date',$val['startdate'], 'Y-m-d') .'</em><a data="{num:'.$key.',objectid:'.$val['parent'].'}" href="javascript:;" id="showdetails">查看明细</a>';
               echo '</div></div>';
               echo '<div class="againterview_detail" id="detail'.$key.'" style="display:none; width:275px; margin-left:50px;"></div>';
               
               if(0){
               echo'
               <div class="contentline_each clearfix"><span>备&nbsp;&nbsp;&nbsp;注：</span>
                  <div class="timelist pull-left">
                     <div class="beizhucolor">此人经验丰富，面试时请着重了解下熟悉技能等等。另外，请注意逻辑是否清晰。</div>
                  </div>
               </div>';
               }
               
            }
         }
      echo'</div></div>';
      exit();
   }
}
